﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CodeStash.Services;
using System.ComponentModel.Composition;

namespace CodeStash.Filters
{

    public class HandleErrorExFilter : HandleErrorAttribute
    {
        private ILoggerService loggerService;

        [ImportingConstructor]
        public HandleErrorExFilter(ILoggerService loggerService) : base()
        {
            this.loggerService = loggerService;
        }

        public override void OnException(ExceptionContext filterContext)
        {
            try
            {

                this.loggerService.Error(string.Format("HandleErrorExFilter : An error occurred, Exception Message was {0}\r\n{1}",
                    filterContext.Exception.Message, filterContext.Exception.StackTrace.ToString()));
            }
            catch {}
            base.OnException(filterContext);

        }

    }
}